import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";

/**
 * codeRuleOrgService - 编码规则租户级 - service
 * @date: 2019-1-11

 */
import request from 'utils/request';
import { parseParameters } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
/**
 * 删除organizationId
 *
 * @param {*} params 传递的参数
 * @returns 删除后的参数
 */

function deleteOrgId(params) {
  var paramsData = params;

  if (params.organizationId) {
    delete paramsData.organizationId;
  }

  return _objectSpread({}, paramsData);
}
/**
 * 删除organizationId
 *
 * @param {*} params 传递的参数
 * @returns 删除后的参数
 */


function deleteOrgIdArr(params) {
  var paramsData = params;

  if (params.organizationId) {
    delete paramsData.organizationId;
  }

  return paramsData.selectedRows;
}
/**
 * ruleCode查询
 * @async
 * @function queryCodeList
 * @param {object} params - 查询条件
 * @param {?string} params.ruleCode - 规则代码
 * @param {?string} params.ruleName - 规则名称
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */


export function queryCodeList() {
  return _queryCodeList.apply(this, arguments);
}
/**
 * ruleCode删除
 * @async
 * @function deleteCodeRule
 * @param {object[]} params.selectedRows - 选中批量删除数据
 * @param {!string} params.selectedRows[].ruleId - 编码规则id
 * @param {!string} params.selectedRows[].objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _queryCodeList() {
  _queryCodeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var params,
        pagination,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
            pagination = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule"), {
              method: 'GET',
              query: deleteOrgId(pagination)
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryCodeList.apply(this, arguments);
}

export function deleteCodeRule(_x) {
  return _deleteCodeRule.apply(this, arguments);
}
/**
 *
 * ruleCode新增
 * @async
 * @function addCodeValue
 * @param {object} params.data - 待保存数据
 * @param {!string} params.data.ruleCode - 规则编码
 * @param {!string} params.data.ruleName - 规则名称
 * @param {!string} params.data.meaning - 层级
 * @param {!string} params.data.tenantName - 租户
 * @returns {object} fetch Promise
 */

function _deleteCodeRule() {
  _deleteCodeRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule"), {
              method: 'DELETE',
              body: deleteOrgIdArr(params)
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _deleteCodeRule.apply(this, arguments);
}

export function addCodeValue(_x2) {
  return _addCodeValue.apply(this, arguments);
}
/**
 *
 * ruleCodeDist查询头数据
 * @async
 * @function queryDist
 * @param {object} params - 查询条件
 * @param {!string} params.ruleId - 规则id
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

function _addCodeValue() {
  _addCodeValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule"), {
              method: 'POST',
              body: deleteOrgId(params)
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _addCodeValue.apply(this, arguments);
}

export function queryDist(_x3) {
  return _queryDist.apply(this, arguments);
}
/**
 *
 * ruleCodeDist删除行数据
 * @async
 * @function deleteDist
 * @param {object[]} params.selectedRows - 选中批量删除数据
 * @param {!string} params.selectedRows[].ruleDistId - 编码规则分发id
 * @param {!string} params.selectedRows[].objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _queryDist() {
  _queryDist = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            param = parseParameters(params);
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule/").concat(params.ruleId), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryDist.apply(this, arguments);
}

export function deleteDist(_x4) {
  return _deleteDist.apply(this, arguments);
}
/**
 * 编码详情查询
 * @async
 * @function queryDetail
 * @param {object} params - 查询条件
 * @param {?string} params.ruleDistId - 规则分发id
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

function _deleteDist() {
  _deleteDist = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule-dist"), {
              method: 'DELETE',
              body: deleteOrgIdArr(params)
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteDist.apply(this, arguments);
}

export function queryDetail(_x5) {
  return _queryDetail.apply(this, arguments);
}
/**
 *
 * ruleCodeDist 更新保存数据
 * @async
 * @function addDistValue
 * @param {object} params.data - 待保存数据
 * @param {!string} params.data.meaning - 层级
 * @param {!string} params.data.levelValue - 值
 * @param {?string} params.data.description - 描述
 * @param {!string} params.data.enabledFlag - 是否启用
 * @returns {object} fetch Promise
 */

function _queryDetail() {
  _queryDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule-detail/").concat(params.ruleDistId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryDetail.apply(this, arguments);
}

export function addDistValue(_x6) {
  return _addDistValue.apply(this, arguments);
}
/**
 *
 * ruleCodeDetail 保存更新行数据
 * @async
 * @function addCodeDetail
 * @param {object} params.data - 待保存数据
 * @param {!number} params.data.orderSeq - 序号
 * @param {!string} params.data.fieldType - 段类型
 * @param {!string} params.data.fieldValue - 段值
 * @param {!string} params.data.dateMask - 日期掩码
 * @param {!string} params.data.resetFrequency - 重置频率
 * @param {!number} params.data.seqLength - 位数
 * @param {!number} params.data.startValue - 开始值
 * @returns {object} fetch Promise
 */

function _addDistValue() {
  _addDistValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule-dist"), {
              method: 'POST',
              body: deleteOrgId(params)
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _addDistValue.apply(this, arguments);
}

export function addCodeDetail(_x7) {
  return _addCodeDetail.apply(this, arguments);
}
/**
 *
 * roleCodeDetail 删除详细行数据
 * @async
 * @function deleteCodeDetail
 * @param {object[]} params.selectedRows - 选中批量删除数据
 * @param {!string} params.selectedRows[].ruleDetailId - 编码规则段码id
 * @param {!string} params.selectedRows[].objectVersionNumber - 版本号
 * @returns {object} fetch Promise
 */

function _addCodeDetail() {
  _addCodeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule-detail"), {
              method: 'POST',
              body: deleteOrgId(params)
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _addCodeDetail.apply(this, arguments);
}

export function deleteCodeDetail(_x8) {
  return _deleteCodeDetail.apply(this, arguments);
}
/**
 *
 * 获取块码
 * @async
 * @function queryCode
 * @param {object} params - 查询条件
 * @param {!string} params.lovCode - 块码code
 * @returns {object} fetch Promise
 */

function _deleteCodeDetail() {
  _deleteCodeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId !== undefined ? "".concat(params.organizationId, "/") : '', "code-rule-detail"), {
              method: 'DELETE',
              body: deleteOrgIdArr(params)
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _deleteCodeDetail.apply(this, arguments);
}

export function queryCode(_x9) {
  return _queryCode.apply(this, arguments);
}

function _queryCode() {
  _queryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _queryCode.apply(this, arguments);
}